﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using com.stockstar.baseinfo.datacontract;

/// <summary>
/// 此类主要用于基金二级页面取运河接口数据
/// 2012-07-30为此类中的接口添加缓存处理
/// </summary>
public class FundCanalInterface
{
    /// <summary>
    /// 二级页面~自选基金的基金信息(代码，简称，净值日期，最新净值，累计净值，单位净值涨跌幅)
    /// 如果是货币基金，最新净值、累计净值分别表示每万份基金单位收益和七日年化收益率(%)
    /// </summary>
    ///<param name="codeString">代码串：格式如：000001,000011,....</param>
    /// <returns></returns>
    public static List<FundNetValueReport> GetFavFundsListInfo(string codeString)
    {
        List<FundNetValueReport> favFundList = new List<FundNetValueReport>();
        try
        {
            var e = new F10ParamEntity("BASE", "V_JRJ_FUND_LATEST_INFO", 2)
            {

                Fields = "FUND_CODE,FUNDSNAME_CNINFO,TYPE,FND_TYPE,TRADEDATE,UNIT_NET,ACCUM_NET,TENTHOU_UNIT_INCM,YEAR_YLD,UNIT_NET_CHNG_PCT",
                Filters = new List<string> { "FUND_CODE-in-str=" + codeString }
            };
            Newtonsoft.Json.Linq.JToken jObjArray = null;
            var total = 0;
            if (F10Query.TryParse(e, false, out jObjArray, out total))
            {
                foreach (var jObj in jObjArray)
                {
                    FundCode fund = new FundCode();
                    fund.Code = jObj.J_String("FUND_CODE");  //代码
                    fund.SimpleName = jObj.J_String("FUNDSNAME_CNINFO"); //简称
                    fund.InvestType = jObj.J_Integer("TYPE", 0); //区分货币型及其他类型
                    fund.SecurityType = jObj.J_Integer("FND_TYPE", 0); //基金类型

                    FundNetValueReport fundcode = new FundNetValueReport();
                    fundcode.FundCode = fund;
                    fundcode.Releasetime = jObj.J_DateTime("TRADEDATE", DateTime.Now);//最新净值日期
                    fundcode.Newvalue = jObj.J_Double("UNIT_NET", 0); //净值
                    fundcode.Allvalue = jObj.J_Double("ACCUM_NET", 0);//累计净值
                    fundcode.Perbonus = jObj.J_Double("TENTHOU_UNIT_INCM", 0);//万份基金单位收益
                    fundcode.Getradio = jObj.J_Double("YEAR_YLD", 0);//最近七日收益折算的年收益率
                    fundcode.BDL = jObj.J_Double("UNIT_NET_CHNG_PCT", 0);//单位净值涨跌幅(复权)-变动率

                    favFundList.Add(fundcode);
                }
            }
        }
        catch (Exception ex) {
            throw new Exception("获取数据这里出了问题");
        }
        return favFundList;
    }
}
